package com.dogstudio.popstart.utils;

import android.content.Context;
import android.graphics.Matrix;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import com.dogstudio.popstart.config.Config;

import java.util.Random;


public class AppUtils {

    public static int getScreenWidth(Context context) {
        final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        final Display display = windowManager.getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getMetrics(displayMetrics);
        boolean isPortrait = displayMetrics.widthPixels < displayMetrics.heightPixels;
        return isPortrait ? displayMetrics.widthPixels
                : displayMetrics.heightPixels;
    }

    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    public static int getStartSize() {
        return Config.SCREEN_WIDTH / Config.SIZE;
    }

    public static int getPanelSize() {
        return Config.SCREEN_WIDTH;
    }

    public static int getRandom() {
        Random random = new Random();
        return random.nextInt(5);
    }

    public static Matrix getScaleMatrix(int bitmapWidth, int drawWidth) {
        Matrix matrix = new Matrix();
        float scale = drawWidth * 1.0f / bitmapWidth;
        matrix.postScale(scale, scale);
        return matrix;
    }


}
